﻿namespace HuwmanCode.Diagnostics.Logging

open System
open System.Globalization
open System.Transactions
open System.Runtime.Serialization
open System.Reflection
open HuwmanCode
open HuwmanCode.Transactions
open HuwmanCode.Diagnostics

/// <summary>
/// The console event writer
/// </summary>
type ConsoleEventWriter() = 
    interface ILogWriter with
        /// <summary>
        /// Writes to the console
        /// </summary>
        member this.Write message =
            let writeColor (msg:Object) c =
                Console.ForegroundColor <- c
                Console.WriteLine(msg)
                Console.ResetColor()

            match message.Level with
            | TraceLevel.Debug -> ConsoleColor.White      |> writeColor message
            | TraceLevel.Info  -> ConsoleColor.Blue       |> writeColor message
            | TraceLevel.Warn  -> ConsoleColor.Magenta    |> writeColor message
            | TraceLevel.Error -> ConsoleColor.Red        |> writeColor message
            | TraceLevel.Fatal -> ConsoleColor.DarkRed    |> writeColor message
            | _ -> failwith "Unsupported trace level!"

    interface IDisposable with
        member this.Dispose () =
            ()
    